const Mock = require('mockjs')

let data = Mock.mock({
  // 'items|30': [{
  //   id: '@id',
  //   title: '@sentence(10, 20)',
  //   'status|1': ['published', 'draft', 'deleted'],
  //   author: 'name',
  //   display_time: '@datetime',
  //   pageviews: '@integer(300, 5000)'
  // }]
  'items|100':[{
    id:"@integer(1, 50)",
    name:"@cname",
    // "questionType |1": ["单选", "多选", "简答"],
    questionType:"@pick(['单选', '多选', '简答'])",
    'number': /[a-z]\d{15,19}/,
    'questionNumber': /[a-z]\d{15,19}/,
    addDate:"@datetime",
    anwser:"@integer(50, 100)"
}]
})
let itemsss = []
for (var i =0; i < 100 ; i++) {
  let o = Mock.mock({
    id:"@integer(1, 50)",
    name:"@cname",
    // "questionType |1": ["单选", "多选", "简答"],
    questionType:"@pick(['单选', '多选', '简答'])",
    'number': /[a-z]\d{15,19}/,
    'timea': '@integer(100, 1000)',
    'questionNumber': /[a-z]\d{15,19}/,
    addDate:"@datetime",
    anwser:"@integer(50, 100)"
  }) 
  itemsss.push(o)

}
console.log(itemsss,'====================================-----kjnnnnnnnnnnnnnnn');

let keyew=[]
// 获取数据列表
module.exports = [
  {
    url: '/vue-admin-template/table/list',
    type: 'get',
    response: (config) => {
        console.log(config)
        if(config.query.keyword.length ===0){
          var page = config.query.page 
          var count = itemsss.length//总共条数
          var pagesize = parseInt(config.query.pagesize) //每页条数
          varpages = Math.ceil(count/pagesize) //共多少页
          var startIndex = (page - 1)  * pagesize //开始下标
          console.log(typeof pagesize,'----------')
          var endIndex = (startIndex + pagesize) < count ? (startIndex + pagesize) : count //结束下标
         var  items= itemsss.slice(startIndex,startIndex+pagesize)
  
        }else{
          keyew = itemsss.filter((item)=>{
            return item.number.includes(config.query.keyword)
          })

          var page = config.query.page 
          var count = keyew.length //总共条数
          var pagesize = parseInt(config.query.pagesize) //每页条数
          var pages = Math.ceil(count/pagesize) //共多少页
          var startIndex = (page - 1)  * pagesize //开始下标
          console.log(typeof pagesize,'----------')
          var endIndex = (startIndex + pagesize) < count ? (startIndex + pagesize) : count //结束下标
         var items= keyew.slice(startIndex,startIndex+pagesize)

        }
       
      return {
        success:true,
        message:"",
        items:items,
        count:count,
        page: page,
        pages: pages,
        pagesize:pagesize
      }
    }
  },


  {
        url: '/vue-admin-template/del',
        type: 'delet',
        response: (config) => {
            console.log(config,'11111111111111111111112222222222222222222222222222334')
            itemsss.forEach((item, index, arr) => {
              if(item.number == config.query.number){
                arr.splice(index,1)
              }
            })
            console.log(itemsss,']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]');
          return {
            success:true,
            message:"",
          }
        }
      }
}


// 删除数据列表

// module.exports = [
//   {
//     url: '/vue-admin-template/del',
//     type: 'delet',
//     response: (config) => {
//         console.log(config)
//         let page = config.query.page 
//         let count = 100 //总共条数
//         let pagesize = parseInt(config.query.pagesize) //每页条数
//         let pages = Math.ceil(count/pagesize) //共多少页
//         let startIndex = (page - 1)  * pagesize //开始下标
//         console.log(typeof pagesize,'----------')
//         let endIndex = (startIndex + pagesize) < count ? (startIndex + pagesize) : count //结束下标
//         let items = []
//         for (; startIndex < endIndex; startIndex++) {
//             let o = Mock.mock({
//               id:"@integer(1, 50)",
//               name:"@cname",
//               // "questionType |1": ["单选", "多选", "简答"],
//               questionType:"@pick(['单选', '多选', '简答'])",
//               'number': /[a-z]\d{15,19}/,
//               'timea': '@integer(100, 1000)',
//               'questionNumber': /[a-z]\d{15,19}/,
//               addDate:"@datetime",
//               anwser:"@integer(50, 100)"
//             }) 
//             items.push(o)
  
//         }
//       console.log(startIndex,endIndex);
//       return {
//         success:true,
//         message:"",
//         items:items,
//         count:count,
//         page: page,
//         pages: pages,
//         pagesize:pagesize
//       }
//     }
//   }
// ]

